<include file="Public:header" />

<link rel="stylesheet" href="__PUBLIC__/css/jquery-ui.css">
<link rel="stylesheet" href="__PUBLIC__/css/jquery-ui.theme.css">

<div class="container">
	<!-- Docs nav ================================================== -->
	<div class="page-header">
		<h4>修改 资讯信息</h4>
	</div>
	<div class="row">
		<div class="span12">
			<include file="Public:alert" />
			<form action="__APP__/index.php/News/edit/" method="post"  enctype="multipart/form-data">
				<input  type="hidden" name="role_id" value="{$Think.session.role_id}"/>
				<input type="hidden" name="id" value="{$vo.id}" />
				<table class="table" border="0" cellspacing="1" cellpadding="0">
					<thead>
						<tr>
							<td colspan="2"><input name="submit" class="btn btn-primary" type="submit" value="保存"/>&nbsp; <input class="btn btn-primary" name="submit" type="submit" value="保存 & 新增"/> &nbsp;<input class="btn" type="button" onclick="javascript:history.go(-1)" value="返回"/></td>
						</tr>
					</thead>
					<tfoot>
						<tr>
							<td colspan="2"><input class="btn btn-primary"  name="submit" type="submit" value="保存"/> &nbsp;<input class="btn btn-primary" type="submit" value="保存 & 新增"/>&nbsp; <input class="btn" type="button" onclick="javascript:history.go(-1)" value="返回"/></td>
						</tr>
					</tfoot>
					<tbody>
						<tr>
							<td class="tdleft">目录</td>
							<td>
								<select name="category_id">
								    <option value="">选择目录</option>
									<volist  name="category_list" id="vvo">
									<option value="{$vvo.id}" <?php if($vo['category_id']==$vvo['id']) echo "selected";?>>{$vvo.name}</option>
									</volist>
								</select>
							</td>
						</tr>
						<tr>
							<td class="tdleft">文章标题</td>
							<td><input class="span3" type="text" name="title" id="title" size="80" placeholder="请输入标题" value="{$vo.title}"></td>
						</tr>
						<tr>
							<td class="tdleft">标题图片</td>
							<td>

								<div>
								<p>图片预览：</p>
								<img id="thumbs" style="max-width:240px;max-height:80px;" src="
								<?php if(!empty($vo['large_thumb'])){?>
								<?php echo 'http://'.FRONT_SITE_NAME.str_replace('./','/',$vo['large_thumb']);?>"
								<?php }?>
								/>
								</div>
								<div style="clear:both;width:100%;height:1px;"></div>
								<div>

									<p><input type="hidden" name="images_url" id="url1" value="" />
										<input type="button" id="image1" value="选择图片" />
									</p>

								</div>

								<!--<style>
								.ncbtn{
								font: 400 12px/20px "microsoft yahei",arial;
								color: #FFF;
								background-color: #ffc314;
								text-align: center;
								vertical-align: middle;
								display: inline-block;
								height: 30px;
								padding: 5px 10px;
								border-radius: 3px;
								cursor: pointer;
								text-decoration: none;
								}

								#tabs>div img{margin:5px;}
								#tabs>div img:hover{cursor:pointer;}
								</style>
								<div>
										2.从相册中选择图片
										<a class="ncbtn picture_insert">打开相册</a>
										<a class="ncbtn picture_close">关闭相册</a>
									<input type="hidden" id="images_url" name="images_url" value=""/>
								</div>-->
								<div id="tabbox" style="width:800px;display:none;">
									<div id="tabs">
									  <ul></ul>
									</div>
								</div>
							</td>
						</tr>
						<tr>
							<td class="tdleft">简单描述</td>
							<td>
								<textarea name="meta_description" id="meta_description" style="width: 800px; height: 50px;">{$vo.meta_description}</textarea>
							</td>
						</tr>
						<tr>
							<td class="tdleft">详情</td>
							<td>
								<textarea name="content" id="content" style="width: 800px; height: 350px;">{$vo.content}</textarea>
							</td>
						</tr>
						<tr>
							<td class="tdleft">排序</td>
							<td><input class="span3" type="text" name="descno" id="descno" placeholder="排序" size="5" value="{$vo.descno}"></td>
						</tr>
						<tr>
							<td class="tdleft">首页显示</td>
							<td>
							 <input type="radio" name="istop" value="1" <if condition="$vo.istop eq 1">checked</if>>  显示
                              <input type="radio" name="istop" value="0" <if condition="$vo.istop eq 0">checked</if>>  不显示
							</td>
						</tr>
						<tr>
							<td class="tdleft">启用</td>
							<td>
                              <input type="radio" name="is_show" value="1" <if condition="$vo.is_show eq 1">checked</if>>  启用
                              <input type="radio" name="is_show" value="0" <if condition="$vo.is_show eq 0">checked</if>>  停用
                            </td>
						</tr>
					</tbody>
				</table>
			</form>

		</div>


	</div>
</div>


<script type="text/javascript">


	<if condition="C('ismobile') eq 1">
		width=$('.container').width() * 0.9;
		$("#content").css({
			width : width
		});
	</if>
	$("input[name='submit']").click(function(){
		if($("#title").val() == null || $("#title").val() == ""){
			alert('文章标题不能为空');
			return false;
		}


		/*if($("select[name='category_id'] option:selected").val()==null||$("select[name='category_id'] option:selected").val()==""){
			alert("目录不能为空");
			return false;
		}*/

		//将编辑器ifreme的值传到textarea
		$("#content").html(editor2.html());
		var content=$("#content").val();
		//alert(content);return false;
		if(content == null || content == ""){
			alert('详情不能为空');
			return false;
		}

	});
	$(".fa-file-text-o").parent().parent().addClass("active");
	$(".fa-indent").parent().parent().addClass("active");
</script>
<!--Kindeditor-->
<script charset="utf-8" src="__PUBLIC__/js/kindeditor/kindeditor-all.js"></script>
<script charset="utf-8" src="__PUBLIC__/js/kindeditor/lang/zh-CN.js"></script>
<script>
    KindEditor.ready(function(K) {
		//文本域编辑器（默认最大宽度为722px，高度等比例）
        var editor2 = K.create('textarea[name="content"]', {
            uploadJson:'__PUBLIC__/js/kindeditor/php/upload_json_news.php?type=1',
            allowFileManager : true,
			//insert_imageWidth:"722", //设置编辑框内默认图片尺寸
			//insert_imageHeight:"80",
            //loadStyleMode : false,
            fileManagerJson: '__PUBLIC__/js/kindeditor/php/file_manager_json_news.php'
        });
		//点击文件元素，弹出kindeditor编辑器的图片窗口，将选择的图片路径存储到隐藏文本中，提交到控制器处理
        K('#image1').click(function() {
			var editor = K.editor({
				//allowFileManager : true,
				uploadJson:'__PUBLIC__/js/kindeditor/php/upload_json_news_thumb.php',
				//loadStyleMode : false,
				fileManagerJson: '__PUBLIC__/js/kindeditor/php/file_manager_json.php'
			});
            editor.loadPlugin('image', function() {
                editor.plugin.imageDialog({
                    imageUrl : K('#url1').val(),
//					imageWidth:"135",
//					imageHeight:"80",
                    clickFn : function(url, title, width, height, border, align) {
                        $("#thumbs").attr("src",url)
                        url = "/Public"+url.replace(/http.*.\/Public/g,"");
                        K('#url1').val(url);
                        editor.hideDialog();
                    }
                });
            });
        });

    });

    $(function () {

    $('#test').click(function () {
		$.ajax({
		    type:'POST',
			url:'__APP__/index.php/News/album_test',

			success:function (response, stutas,xhr) {
				$('#tes').html(response);
            }

		});
    });

//绑定按钮
$(".picture_insert").click(function(){
	$("#tabbox").show()
	if($("#tabs").children().length<=1){
		load_photo_list()
	}

})

$(".picture_close").click(function(){
	$("#tabbox").hide()
})
function load_photo_list(){

//绑定异步加载事件
$.ajax({
type:"GET",
url:"__APP__/index.php/News/album_list/",
dataType:"json",
async:false,
success:function(e){

console.log(e)

var len = e.length
var sub_len = 5;//每页数量控制
var pg=0
var html=""

for(var i = 0; i<len;i++){

	html+="<img src='"+e[i].url_a+"' data-url ='"+e[i].url_b+"' width='135' height='90' />"
	var p = i+1

	if(p<=(len - len%sub_len)){
		if((p/sub_len)%1 === 0){
			$("#tabs>ul").append("<li><a href='#tab_"+(pg+1)+"'>"+(pg+1)+"</a></li>")
			$("#tabs").append("<div id='tab_"+(pg+1)+"'>"+html+"</div>")
			pg = pg+1
			html=""
		}
	}else{
		if(p===len){
			$("#tabs>ul").append("<li><a href='#tab_"+(pg+1)+"'>"+(pg+1)+"</a></li>")
			$("#tabs").append("<div id='tab_"+(pg+1)+"'>"+html+"</div>")
		}
	}

}

$("#tabs div>img").bind("click",function(){
	$("#images_url").val($(this).data("url"))
	$("#thumbs").attr("src",$(this).attr("src"))
})

$( "#tabs" ).tabs();

}

});

}


});

</script>
<include file="Public:footer" />